import { _categroyTreeList, _frontCategory } from '@/api/homePage'
import { Message } from 'element-ui'
import store from '@/store'

const user = {
  state: {

    catoryTressData: [], // 分类数据
    cartNum: '', // 购物车数量
    userInfo: sessionStorage.getItem('userInfo') ? JSON.parse(sessionStorage.getItem('userInfo')) : {} // 登录账号信息

  },

  mutations: {
    SET_CATORYTRESSDATA: (state, catoryTressData) => {
      console.log('555555777555555', catoryTressData)
      state.catoryTressData = catoryTressData
      sessionStorage.setItem('catoryTressData', JSON.stringify(catoryTressData))
    },
    SET_CARTNUM: (state, cartNum) => {
      state.cartNum = cartNum
      sessionStorage.setItem('cartNum', JSON.stringify(cartNum))
    },
    SET_USER_INFO: (state, action) => {
      state.userInfo = action
      sessionStorage.setItem('userInfo', JSON.stringify(state.userInfo))
    },
    CLEAR_DATA: (state) => {
      state.userInfo = '' // 清空存储的数据
    }

  },

  actions: {
    // async getcCategroyList({ commit, state }, callback) {
    //   console.log()
    //   const param = { memberUserId: '145' }
    //   const { result, result: { data }} = await _categroyTreeList(param)
    //   commit('SET_CATORYTRESSDATA', data)
    //   callback(result)
    // }
    async getcCategroyList({ commit, state }, callback) {
      const param = { type: 0 }
      const { result, result: { data }} = await _frontCategory(param)
      commit('SET_CATORYTRESSDATA', data)
      callback(result)
    }

  }
}

export default user
